package com.jabber.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


public class FleetUpEvent {
	
	private String uid;
	private String organizer;
	private String timestamp;
	private String title;
	private String url;
	private String description;
	private String doctrine;
	private String location;
	private Date date;
	
	public FleetUpEvent() {
	}
	
	public void setUid(String uid) {
		this.uid = uid.trim();
	}
	
	public String getUid() {
		return uid;
	}

	public String getOrganizer() {
		return organizer;
	}

	public void setOrganizer(String organizer) {
		this.organizer = organizer.trim();
	}

	public String getTimeStamp() {
		return timestamp;
	}

	public void setTimeStamp(String timestamp) {
		this.timestamp = timestamp;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title.trim();
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url.trim();
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		int begin = description.indexOf("Start Time:") + 12;
		int end = description.indexOf("Doctrine:") - 2;
		
		setTimeStamp(description.substring(begin, end));
		
		begin = description.indexOf("Doctrine:") + 10;
		end = description.indexOf("Link:") - 2;
			
		setDoctrine(description.substring(begin, end));
		
		begin = description.indexOf("Details:") + 9;
		this.description = description.substring(begin);
	}
	
	public String getDoctrine() {
		return doctrine;
	}
	
	public void setDoctrine(String doctrine) {
		this.doctrine = doctrine;
	}
	
	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}
	
	public Date getDate() {
		return date;
	}

	public void setDate(String date) throws ParseException {
		DateFormat format = new SimpleDateFormat("yyyyMMddHHmmssZ", Locale.ENGLISH);
		this.date = format.parse(date.replace("T", "").replace("Z", "").concat("+0000"));
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("==Fleet-Up Op Reminder==\r\n");		
		sb.append("Title: ");
		sb.append(title);
		sb.append("\r\n");
		sb.append("Organizer: ");
		sb.append(organizer);
		sb.append("\r\n");
		sb.append("Time Stamp: ");
		
		double diff = (double) (date.getTime() - new Date().getTime());
		diff = diff / (60 * 60 * 1000);
				
		sb.append(timestamp + " (" + String.format("%.2f", diff) + " hrs)");
		sb.append("\r\n");
		sb.append("Doctrine: ");
		sb.append(doctrine);
		sb.append("\r\n");
		sb.append("Location: ");
		sb.append(location);
		sb.append("\r\n");
		sb.append("Description: ");
		sb.append(description);
		sb.append("\r\n");
		sb.append("URL: ");
		sb.append(url);
		
		return sb.toString();
	}
	
}
